<?php

namespace app\common\validate;

use think\Validate;

class SchoolApply extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'user_id|用户' => 'require',
        'apply_nickname|昵称' => 'require|length:1,20',
        'apply_mobile|手机号' => 'require|mobile',
        'apply_school|学校' => 'require|length:1,20',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'user_id.require' => '用户不能为空',
        'apply_mobile.require' => '手机号不能为空',
        'apply_nickname.length' => '昵称的长度在1-20之间',
        'apply_school.length' => '学校的长度在1-20之间',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [
            'user_id',
            'apply_mobile',
            'apply_nickname',
            'apply_school',
        ],
    ];


    function mobile($mobile)
    {
        $pattern = "/^1[3-9]\d{9}$/";
        if (!preg_match($pattern, $mobile)) {
            return FALSE;
        }
        return TRUE;
    }
}
